package edu.fdzc.system.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.fdzc.system.entity.Accout;
import edu.fdzc.system.entity.Question;
import edu.fdzc.system.mapper.QuestionMapper;
import edu.fdzc.system.service.QuestionService;
import edu.fdzc.system.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public void add(Question question) {
        Accout currentUser = TokenUtils.getCurrentUser();
        question.setTeacherId(currentUser.getId());
        questionMapper.insert(question);
    }

    @Override
    public void updateById(Question question) {
        questionMapper.updateById(question);
    }

    @Override
    public void deleteById(Integer id) {
        questionMapper.deleteById(id);
    }

    @Override
    public void deleteBatch(List<Integer> ids) {
        for(Integer id : ids){
            questionMapper.deleteById(id);
        }
    }

    @Override
    public Question selectById(Integer id) {
        return questionMapper.selectById(id);
    }

    @Override
    public List<Question> selectAll(Question question) {
        return questionMapper.selectAll(question);
    }

    @Override
    public PageInfo<Question> selectPage(Question question, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Question> list = questionMapper.selectAll(question);
        return PageInfo.of(list);
    }
}
